import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";
import Layout from "@/layout/index.vue";

const constantRoutes: RouteRecordRaw[] = [
  {
    path: "/",
    component: Layout,
    redirect: "/dashboard",
    children: [
      {
        path: "dashboard",
        name: "Dashboard",
        component: () => import("@/views/dashboard/index.vue"),
        meta: {
          icon: "ant-design:home-outlined",
          title: "主页",
          affix: true,
          noCache: true
        }
      }
    ]
  },
  {
    path: "/redirect",
    component: Layout,
    meta: {
      hidden: true
    },
    children: [
      {
        path: "/redirect/:path(.*)",
        component: () => import("@/views/baseviews/Redirect.vue")
      }
    ]
  },
  {
    path: "/login",
    name: "Login",
    component: () => import("@/views/login/Login.vue"),
    meta: {
      hidden: true
    }
  }
];

const asyncRoutes: RouteRecordRaw[] = [
  {
    path: "/noshow",
    component: Layout,
    meta: {
      hidden: true,
      title: "隐藏的菜单"
    }
  },
  {
    path: "/documentation",
    component: Layout,
    redirect: "/documentation/index",
    meta: {
      title: "文档库",
      icon: "ant-design:hdd-outlined",
      always: true
    },
    children: [
      {
        path: "index",
        name: "documentation-index",
        component: () => import("@/views/documentation/Documentation.vue"),
        meta: {
          title: "document",
          icon: "ant-design:book-outlined"
        }
      }
    ]
  },
  {
    path: "/guide",
    component: Layout,
    redirect: "/guide/index",
    children: [
      {
        path: "index",
        name: "guide-index",
        component: () => import("@/views/guide/Guide.vue"),
        meta: {
          title: "Guide",
          icon: "ant-design:profile-outlined"
          // noCache: true
        }
      }
    ]
  },
  {
    path: "/system",
    component: Layout,
    redirect: "/system/menu",
    meta: {
      title: "系统",
      icon: "ant-design:tool-outlined",
      breadcrumb: false
    },
    children: [
      {
        path: "menu",
        name: "menu",
        component: () => import("@/views/system/Menu.vue"),
        meta: {
          title: "菜单",
          icon: "ant-design:menu-outlined"
          // affix: true
        }
      },
      {
        path: "role",
        name: "role",
        component: () => import("@/views/system/Role.vue"),
        meta: {
          title: "角色",
          icon: "ant-design:idcard-outlined"
        }
      },
      {
        path: "user",
        name: "user",
        component: () => import("@/views/system/User.vue"),
        meta: {
          title: "人员",
          icon: "ant-design:user-outlined"
        }
      }
    ]
  },
  {
    path: "/external-link",
    component: Layout,
    meta: {
      title: "链接",
      icon: "ant-design:link-outlined"
    },
    children: [
      {
        path: "http://www.baidu.com",
        redirect: "/",
        meta: {
          title: "百度一下",
          icon: "ant-design:baidu-outlined"
        }
      },
      {
        path: "http://www.github.com",
        redirect: "/",
        meta: {
          title: "github",
          icon: "ant-design:github-outlined"
        }
      }
    ]
  },
  {
    path: "/noshowlist",
    component: Layout,
    meta: {
      title: "内部隐藏的菜单"
    },
    children: [
      {
        path: "noshow1",
        component: () => import("@/views/system/Menu.vue"),
        meta: {
          hidden: true,
          title: "隐藏的子菜单1"
        }
      },
      {
        path: "noshow2",
        component: () => import("@/views/system/Menu.vue"),
        meta: {
          hidden: true,
          title: "隐藏的子菜单2"
        }
      },
      {
        path: "noshow3",
        component: () => import("@/views/system/Menu.vue"),
        meta: {
          hidden: true,
          title: "隐藏的子菜单3"
        }
      }
    ]
  },
  {
    path: "/pathparam",
    component: Layout,
    meta: {
      title: "路径参数",
      always: true
    },
    redirect: "/pathparam/:id/detail",
    children: [
      {
        path: ":id/detail",
        component: () => import("@/views/pathparam/PathParam.vue"),
        meta: {
          title: "人员详细信息测试"
        }
      }
    ]
  }
];

export const routes = [...constantRoutes, ...asyncRoutes];

export default createRouter({
  routes: routes, //路由表
  history: createWebHistory() // 路由模式
});
